<?php 

class Event_ShopForm extends Crud_Event_Handler 
{
	protected $_type = 'form';
		
	/**
	 * Run handler with options array.
	 * 
	 * @param Crud_Form $form
	 * @return void
	 */
	public function run($form)
	{
		$element = $form->getElement('city_id');
		
		$peer = CitiesPeer::getInstance();
		$select = $peer->select();
		$select->where(CitiesPeer::HAS_SHOP, 1);
		$select->order('name asc');
		
		$rowset = $peer->fetchAll($select);
		
		$values = array();
		foreach ($rowset as $row) {
			$values[ $row->getId() ] = $row->getName();
		}
		
		$element->clearMultiOptions();
		$element->addMultiOption(null);
		$element->addMultiOptions($values);
	}
}